package main

import (
	"encoding/hex"
	"fmt"
	"gitee.com/kaylee595/m3u8"
	"strings"
)

func main() {
	const data = `#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128,URI="dc2912a1698f6ebd.ts",IV=0x00af03f2224d88b3bf12d87498ae9af8
#EXTINF:4.005333,
1000.ts
#EXTINF:5.006667,
1001.ts
#EXTINF:3.888511,
1002.ts
#EXTINF:5.006667,
1003.ts
#EXTINF:3.921889,
1004.ts
#EXTINF:4.005333,
1005.ts
#EXT-X-ENDLIST`
	playlist, _ := m3u8.ParseMediaPlayList(strings.NewReader(data))
	fmt.Println("version:", playlist.Version)
	fmt.Println("targetDuration:", playlist.TargetDuration)
	fmt.Println("mediaSequence:", playlist.MediaSequence)
	fmt.Println("num of media:", len(playlist.Segments))
	fmt.Println("segment 0 URI:", playlist.Segments[0].URI)
	fmt.Println("segment 0 duration:", playlist.Segments[0].Duration)
	fmt.Println("segment 0 key method:", playlist.Segments[0].Key.Method)
	fmt.Println("segment 0 key URI:", playlist.Segments[0].Key.URI)
	fmt.Println("segment 0 key IV:", hex.EncodeToString(playlist.Segments[0].Key.IV))
	/*
		version: 3
		targetDuration: 6s
		mediaSequence: 0
		num of media: 6
		segment 0 URI: 1000.ts
		segment 0 duration: 4.005333s
		segment 0 key method: AES-128
		segment 0 key URI: dc2912a1698f6ebd.ts
		segment 0 key IV: 00af03f2224d88b3bf12d87498ae9af8
	*/
}
